package com.lingo.ffmpegdemo.lg.utils;

import cn.hutool.core.lang.Console;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Arrays;

/**
 * @author watson
 * @date 2021/5/8 15:01
 * @Description: TODO
 **/
public class FileUtils {

    public static final String OUT_PATH = "D:\\ffmpegMedia\\temp";
    public static int total = 0;

    public static void updateFile(String filePath) {

        File file = new File(filePath);
        String fileName = file.getName();
        System.out.println("filename" + fileName);
        String[] list = file.list();
        try {
            FileInputStream fileInputStream = null;
            FileOutputStream fileOutputStream = null;
            for (int i = 0; i < list.length; i++) {
                total++;
                String strPath = filePath + "\\" + list[i];
                String name = new File(strPath).getName();
                String replace = name.replace("【瑞客 论坛 www.ruike1.com】", "");
                fileInputStream = new FileInputStream(strPath);
//                String outFile = OUT_PATH + "\\" + total + "__" + fileName + (i + 1) + ".mp4";
                String outFile = filePath + "\\"  + name  + ".mp4";
                System.out.println(outFile);
                fileOutputStream = new FileOutputStream(outFile);
                byte[] bytes = new byte[1024 * 10];
                int len = 0;
                while ((len = fileInputStream.read(bytes)) != -1) {
                    fileOutputStream.write(bytes, 0, len);
                }
            }
            fileInputStream.close();//释放资源
            fileOutputStream.close();//释放资源

        } catch (Exception e) {
            e.printStackTrace();
        }


    }

    public static void getFile(String firstPath) {
        File file = new File(firstPath);
        String[] list = file.list();
        Arrays.sort(list);
        Console.log(list);
        File file1 = null;
        for (int i = 0; i < list.length; i++) {
            String filePath = firstPath + "\\" + list[i];
            file1 = new File(filePath);
            if (file1.isDirectory()) {
                updateFile(filePath);
            }
        }
    }


    public static void main(String[] args) {
        Console.log("============begin=========");
        updateFile("E:\\开课吧2020新版\\开课吧2020新版\\12、第十二章 分布式协调服务器zookeeper - 副本");
//        getFile("F:\\网盘下载\\hadoop\\北风网.Python零基础人工智能就业视频教程");
        Console.log("============end=========");
    }
}
